package data;

import hxmath.math.IntVector2;
import hxmath.math.MathTypes.Vector2Type;
import hxmath.geom.Rect;
import hxd.fmt.grd.Data.Color;
import haxe.Json;
import hxd.Rand;
import tree.Root;
import cmd.Root_Cmd;
import tree.LeafKind;
import tree.Leaf;


class Data_Canvas extends Data{
    public var width(get, null) : Int;
    public var height(get, null) : Int;
    public var curLayer(get, null) : Int;
    public var isAutoPlay : Bool;
    public var rangeX(default, null) : IntVector2;
    public var rangeY(default, null) : IntVector2;

    var inner_canvas : InnerData_Canvas;
    public function new() {
        super();
        
    }
    public override function OnEnter(last:LeafKind) {
        super.OnEnter(last);
    }

    public function get_width() {
        return inner_canvas.width;
    }
    public function get_height() {
        return inner_canvas.height;
    }
    public function get_curLayer() {
        return inner_canvas.curLayer;
    }
    
    
    public function SetCanvas(data) {
        inner_canvas = data;
        rangeX = new IntVector2(0, data.width);
        rangeY = new IntVector2(0, data.height);
        Root.instance.AddMsg(RefreshCanvas);
    }
    
    //设置新颜色  返回旧颜色
    public function ChangeColor(x:Int, y:Int, layer:Int, color:Int) {
        return inner_canvas.ChangeColor(x, y, layer, color);
    }

    //获取颜色
    public function GetColor(x:Int, y:Int, layer:Int) {
        return inner_canvas.GetColor(x, y, layer);
    }

    //设置颜色
    public function SetColor(x:Int, y:Int, layer:Int, color:Int) {
        inner_canvas.SetColor(x, y, layer, color);
    }
    
    //改变对应层级的图片
    public function ChangeLayerColors(layer, colors) {
        var opixels = inner_canvas.GetLayerColors(layer);
        inner_canvas.ChangeLayerColors(layer, colors);
        root.AddMsg(RefreshCanvas);
        root.AddMsg(RefreshTimeline);
        return opixels;
    }

    public function GetFinalPixels() {
        return inner_canvas.GetPixels();
    }



}